package com.demo.index;

import java.util.List;

import com.demo.common.model.Blog;
import com.jfinal.core.Controller;

import db.DBHelper;
import db.DataColumn;
import db.DataRow;
import db.DataTable;
import socket.Header;
import socket.HeaderStr;
import socket.SocketClient;
import socket.body.ApplyKey;

/**
 * IndexController
 */
public class IndexController extends Controller {
	public void index() {				
		DBHelper help=new DBHelper();
		String sSQL="select XH,SFXMDM,SFXMMC,DKFLAG,DKCODE,DKDESC,DKJE,JE,YHZH from SCS_YSK_DK";
		
		DataTable dt=help.GetDataTable(sSQL);	
		
		String sSQL2="select * from blog";
		DataTable dt2=help.GetDataTable(sSQL2);	
		setAttr("dt", dt);
		setAttr("dt2", dt2);
		render("index.html");
	}
	public void send() {
		DBHelper help=new DBHelper();
		String sSQL="select XH,SFXMDM,SFXMMC,DKFLAG,DKCODE,DKDESC,DKJE,JE,YHZH from SCS_YSK_DK where XH="+getParaToInt();		
		DataTable dt=help.GetDataTable(sSQL);	
		DataColumn col=dt.GetRow().get(0).GetColumn().get(0);
		
		SocketClient s= new SocketClient();
		Header header=new Header();
		ApplyKey applyKey=new ApplyKey();
		applyKey.settypecode("02");   //交易代码类型 02代扣费   41对账 [2]
		applyKey.setcardno("11111111112222222222");    //银行卡号[20]
		applyKey.setagtcus("111111111122");    //校园卡帐号[12]
		applyKey.setmoney("000000000011");     //金额（分）[12]
		applyKey.setbalance("000000000011");   //余额（分）[12]
		applyKey.setPIN("1111111111222222");       //密码[16]
		applyKey.setagtser("000001");     //发起方流水[6]
		applyKey.setbankser("0000000001");   //银行流水[10]
		applyKey.setdate("20160801");       //交易日期[8]
		applyKey.settime("121320");       //交易时间[6]
		applyKey.setretcode("01");    //返回码[2]
		applyKey.setservuid("00000001");    //代理方标识号[8]
		applyKey.settermid("11111000");     //终端标识号[8]
		applyKey.setmac("12345678");        //MAC[8]
		String str=HeaderStr.getBodyStr(applyKey);
		//str.getBytes("UTF-8");
		String strw=s.sendMessage(str); 
		if (strw.length()<130) {
			System.out.println("报文体长度不够"); 
		}
		strw=strw.substring(0,strw.length());
		System.out.println("报文体："+strw);
		System.out.println("报文体长度："+strw.length());
		String[] arr=HeaderStr.getBody(strw);
		for (String string : arr) {
			System.out.println(string);
		}
	}
}





